package com.ypf.survey.dao.impl;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.ypf.survey.dao.UserDAO;
import com.ypf.survey.model.User;

@Repository
public class UserDAOImpl extends GenericDAOImpl<User, Long> implements UserDAO {

	protected UserDAOImpl() {
		super(User.class.getName());
	}

	@Override
	public User getByCode(String code) {
		DetachedCriteria criteria = DetachedCriteria.forEntityName(entityName);
		criteria.add(Restrictions.eq("code", code));
		return super.findByCriteria(criteria);
	}

	@Override
	public boolean userHasAnswered(Long userId) {
		User user = getById(userId);
		return !user.getAnswers().isEmpty();
	}
}
